// components/CatalogBrand/CatalogBrand.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    brandList: {
      type: Object,
      observer: function (newVal, oldVal, changedPath) {
        if (newVal) {
          this.handleList(newVal)
        }
      }
    },
    height: String
  },

  /**
   * 组件的初始数据
   */
  data: {
    letterArray: [
      "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "X", "Y", "Z"
    ]
  },

  /**
   * 组件的方法列表
   */
  methods: {
    /**
     * 字母点击适应视图
     */ 
    scrollTo(e) {
      let id = e.target.dataset.id
      this.setData({
        "target": id
      })
    },
    handleList(brandList) {
      let label = brandList[0].label
      let letterArray = [label];
      let filteredBrandList = {}
      for (let i =0, l = brandList.length; i < l; i++) {
        let brand = brandList[i]
        if (brand.label === label) {
          if (!filteredBrandList[label]) {
            filteredBrandList[label] = []
          }
          filteredBrandList[label].push(brand)
        } else {
          label = brand.label
          letterArray.push(label)
          if (!filteredBrandList[label]) {
            filteredBrandList[label] = []
          }
          filteredBrandList[label].push(brand)
        }
      }
    
      this.setData({
        filteredBrandList
      })
    }
  }
})
